class SignController < ApplicationController
  layout 'sign'
  
  def index
  end
  
  def in
    session[:user_id] = nil
    if request.post?
      user = User.authenticate(params[:name], params[:password])
      if user
        session[:user_id] = user.id
        uri = session[:origin_uri]
        session[:origin_uri] = nil
        redirect_to(uri || {:controller => 'articles', :action => 'index'})
      else
        flash[:notice] = "Invalid user/password combination: name=#{params[:name]}, password=#{params[:password]}."
      end
    end
  end
  
  def out
    session[:user_id] = nil
    flash[:notice] = "Signed out."
    redirect_to :controller => 'articles', :action => 'index'
  end
end
